﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Automapping.Alterations;
using TrilhaImovel.Core.Entities;
using FluentNHibernate.Automapping;

namespace TrilhaImovel.Data.NHibernateMaps
{
    public class EstateMap : IAutoMappingOverride<Estate>
    {
        public void Override(AutoMapping<Estate> mapping)
        {
            mapping.Table("Estate");

            mapping.Id(x => x.Id).Column("EstateId");

            mapping.Component<PointLocation>( x => x.PointLocation, m =>
                {
                    m.Map(x => x.Latitude, "Latitude");
                    m.Map(x => x.Longitude, "Longitude");
                });

            mapping.Map(x => x.PriceOrRentValue).Column("PriceOrRentValue");

            mapping.Map(x => x.NumberOfRooms).Column("NumberOfRooms");

            mapping.Map(x => x.AreaInSquareMeter).Column("AreaInSquareMeter");

            mapping.Component<Address>(x => x.Address, m =>
            {
                m.Map(x => x.Street).Column("Street")
                        .Length(100)
                        .Not.Nullable();

                m.Map(x => x.Neighborhood).Column("Neighborhood")
                        .Length(100)
                        .Not.Nullable();

                m.Map(x => x.City).Column("City")
                        .Length(100)
                        .Not.Nullable();

                m.Map(x => x.State).Column("State")
                        .Length(2)
                        .Not.Nullable();

                m.Map(x => x.ZipCode).Column("ZipCode")
                        .Length(8)
                        .Not.Nullable();
            });

            mapping.Map(x => x.OperationType).Column("OperationType")
                        .Not.Nullable()
                        .CustomType(typeof(OperationType));

            mapping.Map(x => x.MarkerType).Column("MarkerType")
                        .Not.Nullable()
                        .CustomType(typeof(MarkerType));
            
            mapping.Map(x => x.PropertyType, "PropertyType")
                    .Not.Nullable()
                    .CustomType(typeof(PropertyType));

            mapping.References<RealEstateAgency>(x => x.RealStateAgency).Column("RealEstateAgencyId");
        }
    }
}
